package com.kl.listen;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

@Component
public class MyApplicationRunner implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("测试ApplicationRunner接口: " + new Date());
        System.out.println("获取到的参数列表 = " + args.getOptionNames());
        System.out.println("获取到的参数 = " + args.getNonOptionArgs());
        System.out.println("获取的参数 = " + Arrays.toString(args.getSourceArgs()));
        myTimer();
    }

    public static void myTimer(){
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("这是一个定时任务");
            }
        },0,2000);
    }
}
